package thread;

public class Demo20 {

    public static void main(String[] args) throws InterruptedException {
        Thread t1 = new Thread(()->{
            for(int i = 0; i < 5; i++ ){
                System.out.println("这是t1线程");

                try {
                    Thread.sleep(1000);
                } catch (InterruptedException e) {
                    throw new RuntimeException(e);
                }
            }
            System.out.println("t1线程执行结束");
        });

        Thread t2 = new Thread(()->{
           for(int i = 0; i < 3; i++){
               System.out.println("这是t2线程");
               try {
                   Thread.sleep(1000);
               } catch (InterruptedException e) {
                   throw new RuntimeException(e);
               }
           }
            try {
                //t2线程 等待 t1线程
                t1.join();
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }
            System.out.println("t2线程结束");
        });


        t1.start();
        t2.start();
        System.out.println("main线程开始等待");
        t1.join();
        t2.join();
        System.out.println("main线程等待结束");


    }

}
